package com.whfc.ms.api.emp.controller;

import com.whfc.common.result.ListData;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.emp.dto.AppWorkTypeDTO;
import com.whfc.emp.param.WorkTypeAddParam;
import com.whfc.emp.param.WorkTypeEditParam;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.emp.service.MsAppEmpWorkService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * @author sun_guodong
 * @description 人员模块-系统设置
 * @date 2020-10-29
 */
@RequiresPermissions("emp/workType")
@RestController
@RequestMapping("/ms/api/emp")
public class AppEmpSettingController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MsAppEmpWorkService msAppEmpWorkService;

    @GetMapping(value = "/workType/list", params = {"pageNum", "pageSize"})
    public Result workTypeList(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                               @RequestParam("deptId") Integer deptId,
                               @RequestParam("pageNum") Integer pageNum,
                               @RequestParam("pageSize") Integer pageSize) {
        logger.info("工种列表(分页),loginer:{},deptId:{},pageNum:{},pageSize:{}", user.getUsername(), deptId, pageNum, pageSize);
        PageData<AppWorkTypeDTO> pageData = msAppEmpWorkService.workTypeList(deptId, pageNum, pageSize);
        return ResultUtil.success(pageData);
    }

    @GetMapping(value = "/workType/list")
    public Result workTypeList(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                               @RequestParam("deptId") Integer deptId) {
        logger.info("工种列表(不分页),loginer:{},deptId:{}", user.getUsername(), deptId);
        ListData<AppWorkTypeDTO> listData = msAppEmpWorkService.workTypeList(deptId);
        return ResultUtil.success(listData);
    }

    @RequiresPermissions("emp/workType/add")
    @PostMapping("/workType/add")
    public Result workTypeAdd(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                              @Validated @RequestBody WorkTypeAddParam param) {
        logger.info("添加工种,loginer:{},param:{}", user.getUsername(), param.toString());
        msAppEmpWorkService.workTypeAdd(param);
        return ResultUtil.success();
    }

    @RequiresPermissions("emp/workType/edit")
    @PostMapping("/workType/edit")
    public Result workTypeEdit(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                               @Validated @RequestBody WorkTypeEditParam param) {
        logger.info("编辑工种,loginer:{},param:{}", user.getUsername(), param.toString());
        msAppEmpWorkService.workTypeEdit(param);
        return ResultUtil.success();
    }

    @RequiresPermissions("emp/workType/delete")
    @PostMapping("/workType/del/{id}")
    public Result workTypeDel(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                              @PathVariable("id") Integer id) {
        logger.info("删除工种,loginer:{},id:{}", user.getUsername(), id);
        msAppEmpWorkService.workTypeDel(id);
        return ResultUtil.success();
    }

}
